home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / gameengi.bas < prev    next >
BASIC Source File  |  1998-01-29  |  12KB  |  340 lines

  1. Attribute VB_Name = "GameEngine"
  2. Type MsgWindow
  3.   Caption As String
  4.   Active As Boolean
  5.   Text As String
  6. End Type
  7. Global MessageWindow As MsgWindow
  8. Type EngineCntrls
  9.   InterruptGame As Boolean
  10.   ReasonForInterrupt As Integer
  11. End Type
  12. Public EngineControls As EngineCntrls
  13. Type GameWindow
  14.   PortRect As RECT
  15.   Enabled As Boolean
  16.   Height As Integer
  17.   Width As Integer
  18. End Type
  19. Public RadarWindow As GameWindow
  20. Public BattleViewPort As GameWindow
  21. Public GameControlPanel As GameWindow
  22. Public RadarButton As GameWindow
  23. Public Const MAXBUILDWINDOWS = 3
  24. Public BuildWindows(MAXBUILDWINDOWS) As GameWindow
  25. Type ViewProperties
  26.   MaxScrollSpeed As Integer
  27.   ScrollSpeedEW As Integer
  28.   ScrollSpeedNS As Integer
  29.   Left As Integer
  30.   Top As Integer
  31.   MaxLeft As Integer
  32.   MaxTop As Integer
  33.   Width As Integer
  34.   Height As Integer
  35. End Type
  36. Public View As ViewProperties
  37. Global Const DIRECTION_UP = 1
  38. Global Const DIRECTION_RIGHT = 2
  39. Global Const DIRECTION_DOWN = 3
  40. Global Const DIRECTION_LEFT = 4
  41. 'Interrupt Reasons
  42. Public Const IR_PLAYEREXITEDGAME = 1
  43. Type EngDat
  44.   Episode As Integer
  45.   Level As Integer
  46.   HeartBeat As Integer
  47. End Type
  48. Public EngineData As EngDat
  49. Public GameDataFile$
  50. Global Const GameCycleTime = 0.02
  51. Private Type LevelSettingsType
  52.   AirFriction As Single
  53.   Seed As Integer
  54.   Description As String
  55.   GravityAmount As Integer
  56.   Episode As Integer
  57.   Level As Integer
  58. End Type
  59. Global LevelSettings As LevelSettingsType
  60. Public Sub ResetGame()
  61. For I = 1 To ObjectsActive
  62.   Call Entities.ResetObject(I)
  63. Next I
  64. ObjectsActive = 0
  65. Call ResetMap
  66. End Sub
  67. Public Sub Initialize_GameEngine()
  68. End Sub
  69. Public Sub LoadLevel(Episode, Level, Seed)
  70. SoundData.DeviceOn = False
  71. Randomize Seed
  72. Call SpawnObject(Entities.GetClassNum("EDF_BASEBUILDER"), 1, 7, 7, 0, 0, 0)
  73. For I = 1 To 6
  74.   Putx = Int(MaxMapX * Rnd) + 1
  75.   Puty = Int(MaxMapY * Rnd) + 1
  76.   If GroundBlocks(Putx, Puty).Occupied = False Then
  77.     If Int(2 * Rnd) = 1 Then
  78.       Call SpawnObject(1, 2, Putx, Puty, 0, 0, 0)
  79.     Else
  80.       Call SpawnObject(4, 2, Putx, Puty, 0, 0, 0)
  81.     End If
  82.   End If
  83. Next I
  84. For I = 1 To 7
  85.   Putx = Int(6 * Rnd) + 3
  86.   Puty = Int(6 * Rnd) + 3
  87.   If GroundBlocks(Putx, Puty).Occupied = False Then
  88.     newobj = SpawnObject(1, LocalPlayer.PlayerIndex, Putx, Puty, 0, 0, 0)
  89.     Objects(newobj).Position.Z = GroundBlocks(Objects(newobj).MapPosition.X, Objects(newobj).MapPosition.Y).Height
  90.   End If
  91. Next I
  92. Call Map.GenerateRandomMap(MaxMapX - 12, MaxMapY - 12, SEASON_SUMMER, 5, 5, 10, 70, 3, 3, 5, 5, 3, 4, 30, 4, 3, 4, 6, 3, 10)
  93. SoundData.DeviceOn = True
  94. End Sub
  95. Public Sub StartNewGame(StartingEpisode, StartingLevel, Faction)
  96. Call ResetGame
  97. Call ResetGameEngine
  98. 'Temporary
  99. LocalPlayer.PlayerIndex = SpawnPlayer(FACTION_EDF, 9999, 1)
  100. Player(LocalPlayer.PlayerIndex).Faction = Faction
  101. NewCompPlayer = SpawnPlayer(FACTION_EDF, 9999, 1)
  102. Call AI.GenerateComputerPlayer(1, NewCompPlayer)
  103. LevelSettings.Episode = StartingEpisode
  104. LevelSettings.Level = StartingLevel
  105. Call LoadLevel(StartingEpisode, StartingLevel, 5 * Rnd)
  106. GameResult = RunGame
  107. End Sub
  108. Public Sub StartNewInternetGame(Seed)
  109. Call ResetGameEngine
  110. Call Internet.GetCurrentGameFromServer
  111. GameResult = RunGame
  112. Call Internet.Disconnect
  113. End Sub
  114. Public Sub Initialize_GameWindows()
  115. GameControlPanel.PortRect.Top = ResolutionY - GAMECONTROLPANELSIZE
  116. GameControlPanel.PortRect.bottom = ResolutionY
  117. GameControlPanel.PortRect.Left = 0
  118. GameControlPanel.PortRect.Right = ResolutionX
  119. GameControlPanel.Height = GameControlPanel.PortRect.bottom - GameControlPanel.PortRect.Top
  120. GameControlPanel.Width = GameControlPanel.PortRect.Right - GameControlPanel.PortRect.Left
  121. For I = 1 To MAXBUILDWINDOWS
  122.   BuildWindows(I).PortRect.Top = Int(((GameControlPanel.Height / 2) - (BUILDWINDOWSIZE / 2)) + GameControlPanel.PortRect.Top)
  123.   BuildWindows(I).PortRect.bottom = BuildWindows(I).PortRect.Top + BUILDWINDOWSIZE
  124.   BuildWindows(I).PortRect.Left = ((BUILDWINDOWSIZE) * (I - 1)) + 5
  125.   BuildWindows(I).PortRect.Right = BuildWindows(I).PortRect.Left + BUILDWINDOWSIZE
  126.   BuildWindows(I).Height = BuildWindows(I).PortRect.bottom - BuildWindows(I).PortRect.Top
  127.   BuildWindows(I).Width = BuildWindows(I).PortRect.Right - BuildWindows(I).PortRect.Left
  128. Next I
  129.  
  130. BattleViewPort.PortRect.Top = 0
  131. BattleViewPort.PortRect.bottom = ResolutionY - GAMECONTROLPANELSIZE
  132. BattleViewPort.PortRect.Left = 0
  133. BattleViewPort.PortRect.Right = ResolutionX
  134. BattleViewPort.Height = BattleViewPort.PortRect.bottom - BattleViewPort.PortRect.Top
  135. BattleViewPort.Width = BattleViewPort.PortRect.Right - BattleViewPort.PortRect.Left
  136. RadarWindow.PortRect.Top = GameControlPanel.PortRect.Top - RADARWINDOWSIZE
  137. RadarWindow.PortRect.bottom = RadarWindow.PortRect.Top + RADARWINDOWSIZE
  138. RadarWindow.PortRect.Left = ResolutionX - RADARWINDOWSIZE
  139. RadarWindow.PortRect.Right = RadarWindow.PortRect.Left + RADARWINDOWSIZE
  140. RadarButton.PortRect.Top = GameControlPanel.PortRect.Top + (GameControlPanel.Height / 2) - 5
  141. RadarButton.PortRect.bottom = RadarButton.PortRect.Top + 10
  142. RadarButton.PortRect.Left = (ResolutionX - RADARWINDOWSIZE) - 10
  143. RadarButton.PortRect.Right = ResolutionX
  144. RadarButton.Height = RadarButton.PortRect.bottom - RadarButton.PortRect.Top
  145. RadarButton.Width = RadarButton.PortRect.Right - RadarButton.PortRect.Left
  146. End Sub
  147.  
  148. Public Sub Initialize_BattleView()
  149. Select Case ResolutionY
  150. Case 200
  151.   GameEngine.View.MaxScrollSpeed = 10
  152.   GraphicsEngineData.TerrainRefreshSize = 1
  153. Case 400
  154.   GameEngine.View.MaxScrollSpeed = 20
  155.   GraphicsEngineData.TerrainRefreshSize = 2
  156. Case 480
  157.   GameEngine.View.MaxScrollSpeed = 20
  158.   GraphicsEngineData.TerrainRefreshSize = 3
  159. Case 600
  160.   GameEngine.View.MaxScrollSpeed = 20
  161.   GraphicsEngineData.TerrainRefreshSize = 4
  162. End Select
  163.  
  164. GameEngine.View.Width = BattleViewPort.Width
  165. GameEngine.View.Height = BattleViewPort.Height
  166. GameEngine.View.MaxLeft = ((Map.BattleMap.Width * MapBlockSize) - GameEngine.View.Width) + MapBlockSize
  167. GameEngine.View.MaxTop = ((Map.BattleMap.Height * MapBlockSize) - GameEngine.View.Height) + MapBlockSize
  168. If GameEngine.View.MaxLeft < 0 Then GameEngine.View.MaxLeft = 0
  169. If GameEngine.View.MaxTop < 0 Then GameEngine.View.MaxTop = 0
  170. End Sub
  171. Public Sub ResetEngine()
  172. EngineControls.InterruptGame = False
  173. End Sub
  174. Private Sub ResetGameEngine()
  175. ViewForm.KeyboardInputBox.Text = ""
  176. Call ResetEngine
  177. Call KillAllPlayers
  178. Call GameInterface.ClearKeyStates
  179. Call GameInterface.InitializeInterface
  180. End Sub
  181. Public Function PopupMessageWindow(WndCap, WndTxt)
  182.     MessageWindow.Active = True
  183. MessageWindow.Caption = WndCap
  184. MessageWindow.Text = WndTxt
  185. Do
  186.   DoEvents
  187.   Call GraphicsEngine.ClearBackBuffer
  188.   Call GraphicsEngine.SplashGraphic(InGameConstants(InGameConstant_PICINDEX_ProgramBackground))
  189.   Call GraphicsEngine.DisplayMessageWindow
  190.   Call GraphicsEngine.SwapScreen
  191.   For I = 1 To 5
  192.     If Mouse.ButtonStates(I) = True Then Exit Do
  193.   Next I
  194. Loop
  195. Mouse.ButtonStates(I) = False
  196. MessageWindow.Active = False
  197. End Function
  198. Public Function RunGame() As Integer
  199. Const MAXTICKS = 1
  200. Dim Ticks(MAXTICKS) As Integer, HeartBeatInt As Integer
  201. MaxMessages = 4
  202. Call Sound.Stop_Sounds
  203. Call Sound.Play_LoopSound(Sound.GetSoundIndex("music"), 0)
  204. Call GraphicsEngine.RedrawControlPanel
  205. Call RenderTerrain
  206. Do
  207.                 HeartBeatInt = HeartBeatInt + 10
  208.                 If HeartBeatInt > 360 Then HeartBeatInt = 1
  209.                 GameEngine.EngineData.HeartBeat = (SinTable(HeartBeatInt) * 100) + 155
  210.                 CounterStartTime = Timer
  211.                 
  212.                 DoEvents
  213.                 
  214.   
  215.   For I = 1 To MAXTICKS
  216.     Ticks(I) = Ticks(I) + 1
  217.   Next I
  218.   If Ticks(1) > 20 Then
  219.     Ticks(1) = 0
  220.     For I = 1 To MaxMessages - 1
  221.       InternetMessageBox.LinesActive(I) = InternetMessageBox.LinesActive(I + 1)
  222.      InternetMessageBox.TextLines(I) = InternetMessageBox.TextLines(I + 1)
  223.     Next I
  224.     InternetMessageBox.LinesActive(MaxMessages) = False
  225.   End If
  226.   Call RunMisc
  227.   If Internet.ServerData.ConnectedToServer = True Then
  228.     Call Internet.IncomingDataHandler
  229.   End If
  230.   Call Players.RunBuilds
  231.   Call Music.KeepMusicPlaying
  232.   Call RunCom